import { createRouter } from 'vue-router'

// 增强 push 方法 和 replace 方法
const methods = ['push', 'replace']

methods.forEach((method) => {
  // 缓存对应的方法
  const origin = createRouter.prototype[method]

  createRouter.prototype[method] = function (path: string, successCb: any, errorCb: any) {
    console.log(path, successCb, errorCb)

    if (successCb || errorCb) {
      origin.call(this, path, successCb, errorCb)
    } else {
      // 执行跳转的逻辑即可
      origin.call(this, path, () => {})
    }
  }
})
